﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace AimGameLibrary.GameObject
{

    public class GameVector2 : GameBaseValue
    {
        protected Vector2 myvector2;
        public Vector2 Myvector2 { get { myvector2 = (Vector2)GetParentValue(); return myvector2; } set { myvector2 = value; SetParentValue(myvector2); } }

        public override void LoadData(Identification getdata, int IndexData, NodeData node)
        {
            InputMode = (NodeInputMode)getdata.Items.GetValue(IndexData + 1);

            if (InputMode == NodeInputMode.Vector2_1)
                Listnameparent.Add(node.Data);
            else if (InputMode == NodeInputMode.Float_2)
            {
                String Temp = node.Data;
                Listnameparent.Add(Script.GetName(Temp, 2, 0));
                Listnameparent.Add(Script.GetName(Temp, 2, 1));
            }
            else Myvector2 = (Vector2)getdata.Items.GetValue(IndexData + 2);
        }

        protected override object GetParentValue()
        {
            if (Listparent.Count > 0)
            {
                if (InputMode == NodeInputMode.Vector2_1
                    && Listparent[0].GetType() == typeof(GameVector2))
                {
                        GameVector2 tempvector2 = (GameVector2)Listparent[0];
                        return tempvector2.Myvector2;
                }
                else if (InputMode == NodeInputMode.Float_2
                    && Listparent.Count == 2)
                {
                    if(Listparent[0].GetType() == typeof(GameFloat) && Listparent[1].GetType() == typeof(GameFloat))
                    {
                            GameFloat tempfloatX = (GameFloat)Listparent[0];
                            GameFloat tempfloatY = (GameFloat)Listparent[1];
                            return new Vector2(tempfloatX.MyfloaT, tempfloatY.MyfloaT);
                    }else return myvector2;
                }
                else return myvector2;
            }
            else return myvector2;
        }

        protected override void SetParentValue(object obj)
        {
            if (Listparent.Count > 0)
            {
                if (InputMode == NodeInputMode.Vector2_1)
                {
                    if (Listparent[0].GetType() == typeof(GameVector2))
                    {
                        GameVector2 tempvector2 = (GameVector2)Listparent[0];
                        tempvector2.Myvector2 = (Vector2)obj;
                    }
                }
                else if (InputMode == NodeInputMode.Float_2)
                { 
                    if(Listparent.Count == 2)
                        if(Listparent[0].GetType() == typeof(GameFloat) && Listparent[1].GetType() == typeof(GameFloat))
                        {
                            GameFloat tempfloatX = (GameFloat)Listparent[0];
                            GameFloat tempfloatY = (GameFloat)Listparent[1];
                            Vector2 tempobj = (Vector2)obj;
                            tempfloatX.MyfloaT = tempobj.X;
                            tempfloatY.MyfloaT = tempobj.Y;
                        }
                }
            }
        }

    }
}
